package com.zhonghui.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhonghui.response.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhonghui.common.annotation.Log;
import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.core.domain.AjaxResult;
import com.zhonghui.common.enums.BusinessType;
import com.zhonghui.mes.domain.MesErrorManagement;
import com.zhonghui.mes.service.IMesErrorManagementService;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.common.core.page.TableDataInfo;

/**
 * 防错管理Controller
 * 
 * @author zhonghui
 * @date 2022-05-24
 */
@Api(tags="制造执行MES-防错管理")
@RestController
@RequestMapping("/mes/errorManagement")
public class MesErrorManagementController extends BaseController
{
    @Autowired
    private IMesErrorManagementService mesErrorManagementService;

    /**
     * 查询防错管理列表
     */
    @ApiOperation("查询防错管理列表")
    @GetMapping("/list")
    public TableDataInfo<List<MesErrorManagement>> list(MesErrorManagement mesErrorManagement)
    {
        startPage();
        List<MesErrorManagement> list = mesErrorManagementService.selectMesErrorManagementList(mesErrorManagement);
        return getDataTable(list);
    }

    /**
     * 导出防错管理列表
     */
    @ApiOperation("导出防错管理列表")
    @Log(title = "防错管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesErrorManagement mesErrorManagement)
    {
        List<MesErrorManagement> list = mesErrorManagementService.selectMesErrorManagementList(mesErrorManagement);
        ExcelUtil<MesErrorManagement> util = new ExcelUtil<MesErrorManagement>(MesErrorManagement.class);
        util.exportExcel(response, list, "防错管理数据");
    }

    /**
     * 获取防错管理详细信息
     */
    @ApiOperation("获取防错管理详细信息")
    @GetMapping(value = "/{id}")
    public BaseResult<MesErrorManagement> getInfo(@PathVariable("id") Long id)
    {
        return BaseResult.success(mesErrorManagementService.selectMesErrorManagementById(id));
    }

    /**
     * 新增防错管理
     */
    @ApiOperation("新增防错管理")
    @Log(title = "防错管理", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResult<Integer> add(@RequestBody MesErrorManagement mesErrorManagement)
    {
        return BaseResult.success(mesErrorManagementService.insertMesErrorManagement(mesErrorManagement));
    }

    /**
     * 修改防错管理
     */
    @ApiOperation("修改防错管理")
    @Log(title = "防错管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResult<Integer> edit(@RequestBody MesErrorManagement mesErrorManagement)
    {
        return BaseResult.success(mesErrorManagementService.updateMesErrorManagement(mesErrorManagement));
    }

    /**
     * 删除防错管理
     */
    @ApiOperation("删除防错管理")
    @Log(title = "防错管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public BaseResult<Integer> remove(@PathVariable Long[] ids)
    {
        return BaseResult.success(mesErrorManagementService.deleteMesErrorManagementByIds(ids));
    }
}
